home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / WASTE 1.0a4 Distribution / Demo Source / WEDemoInit.p < prev    next >
Text File  |  1994-02-18  |  2KB  |  109 lines

  1. unit DemoInit;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { Initialization & Finalization Routines }
  5.  
  6. { Copyright © 1993-1994 Merzwaren }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         DemoIntf;
  12.  
  13.     function Initialize: OSErr;
  14.     procedure Finalize;
  15.  
  16. implementation
  17.     uses
  18.         DemoEvents, DemoMenus, DemoWindows;
  19.  
  20.     function Initialize: OSErr;
  21.  
  22.         const
  23.             kMinSystemVersion = $700;
  24.             kScrapThreshold = 4 * 1024;
  25.  
  26.         var
  27.             response: LongInt;
  28.             scrapResult: LongInt;
  29.  
  30.         procedure CheckErr (err: OSErr);
  31.         begin
  32.             if (err <> noErr) then
  33.                 begin
  34.                     Initialize := err;
  35.                     ErrorAlert(err);
  36.                     Exit(Initialize);
  37.                 end;
  38.         end;  { CheckErr }
  39.  
  40.     begin
  41.         Initialize := noErr;
  42.  
  43. { expand the zone to its maximum size }
  44.         MaxApplZone;
  45.  
  46. { allocate some extra master pointer blocks }
  47.         MoreMasters;
  48.         MoreMasters;
  49.         MoreMasters;
  50.         MoreMasters;
  51.  
  52. { initialize the Toolbox }
  53.         InitGraf(@thePort);
  54.         InitFonts;
  55.         InitWindows;
  56.         InitMenus;
  57.         TEInit;
  58.         InitDialogs(nil);
  59.         InitCursor;
  60.         FlushEvents(everyEvent, 0);
  61.  
  62. { if desk scrap is too large, unload it }
  63.         if (InfoScrap^.scrapSize > kScrapThreshold) then
  64.             scrapResult := UnloadScrap;
  65.  
  66. { make sure system software version is 7.0 or newer }
  67.         if (Gestalt(gestaltSystemVersion, response) <> noErr) | (response < kMinSystemVersion) then
  68.             begin
  69.                 response := Alert(kAlertNeedSys7, nil);
  70.                 Initialize := -1;
  71.                 Exit(Initialize);
  72.             end;
  73.  
  74. { determine whether Color QuickDraw is available }
  75.         gHasColorQD := (Gestalt(gestaltQuickDrawVersion, response) = noErr) & (response >= gestalt8BitQD);
  76.  
  77. { determine whether the Text Services Manager is available }
  78.         gHasTextServices := (Gestalt(gestaltTSMgrVersion, response) = noErr);
  79.  
  80. { register this application with the TSM }
  81.         if (gHasTextServices) then
  82.             CheckErr(InitTSMAwareApplication);
  83.  
  84. { perform other initialization chores }
  85.         CheckErr(InitializeEvents);
  86.         CheckErr(InitializeMenus);
  87.  
  88.     end;  { Initialize }
  89.  
  90.     procedure Finalize;
  91.         var
  92.             window: WindowPtr;
  93.             err: OSErr;
  94.     begin
  95.  
  96. { close all windows }
  97.         repeat
  98.             window := FrontWindow;
  99.             if (window <> nil) then
  100.                 DestroyWindow(window);
  101.         until (window = nil);
  102.  
  103. { notify text services that we're closing down }
  104.         if (gHasTextServices) then
  105.             err := CloseTSMAwareApplication;
  106.  
  107.     end;  { Finalize }
  108.  
  109. end.